<template>
    <div style="padding:20px 20px 20px 20px;background:#fff;">
      <el-table :data="list.slice((currentPage-1)*pagesize,currentPage*pagesize)" style="width: 100%"
        row-key="id" border lazy :load="load" id="exportTable"
        :tree-props="{children: 'son', hasChildren: 'hasChildren'}">
      <el-table-column prop="id" label="产品ID" align="center" width="80"></el-table-column>
      <el-table-column prop="name" label="产品名称" align="center" width="200"></el-table-column>
      <el-table-column prop="cate_name" label="产品分类" align="center" width="120"></el-table-column>
      <el-table-column prop="img" label="产品图片" align="center" width="100">
          <template slot-scope="scope">            
              <img :src="imgUrl+scope.row.img" width="70" height="50" />
          </template>  
      </el-table-column>
      <el-table-column prop="lable" align="center" label="产品单位" width="100"></el-table-column>
      <el-table-column prop="price" align="center" label="产品价格" width="130"></el-table-column>
      <el-table-column prop="num" align="center" label="产品库存" width="80"></el-table-column>
      <el-table-column prop="remark" align="center" label="产品备注" width="200"
      :show-overflow-tooltip="true"></el-table-column>
      <el-table-column
          fixed="right"
          label="操作"
          width="120" align="center">
          <template slot-scope="scope">
            <el-button @click="edit(scope.row)" type="primary" icon="el-icon-edit" size="small"></el-button>
            <el-popconfirm title="确定要删除吗?" @confirm="del(scope.row.id,scope)">
                <el-button type="primary" size="small" icon="el-icon-delete" slot="reference"
                ></el-button>
            </el-popconfirm>
            
            <!--<el-button @click="del(scope.row.id)" type="primary" 
            icon="el-icon-delete" size="small"></el-button>-->
          </template>
        </el-table-column>
        
    </el-table>
    <el-pagination
      class="fen"
      background
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="currentPage"
      :page-size="pagesize"
      :page-sizes="[5, 10, 20, 50]"      
      layout="total, sizes, prev, pager, next, jumper"
      :total="list.length">
      </el-pagination>
</div>
</template>
<script>
export default {
  name: 'goodsTable',
  props:['list'],
  data(){
      return {
          currentPage:1, //初始页
          pagesize:10, //每页的数据
          show_page:true,
          nowpage:1,
          maxpage:10,
          imgUrl:this.url,
      }
  },
  methods: {
    handleSizeChange: function (size) {
        this.pagesize = size;
    },
    handleCurrentChange: function(currentPage){
      this.currentPage = currentPage;
    },
    changeLeft($event){
        $event.currentTarget.className="active";
    },
    removeLeft($event){
        $event.currentTarget.className ="tdclass";
    },
    load(tree, treeNode, resolve) {
      setTimeout(() => {
        resolve()
      }, 1000)
    },
    edit:function(item){
      this.$emit("func",{'key':'editShow','item':item})
    },
    del:function(id,scope){
      var index = scope.$index
      var that = this
      this.$del('goods/del',{id:id}).then((res) => {
        if(res.code == 1){
            that.$message.success(res.msg);
            that.list.splice(index,1)
        }else{
          that.$message.error(res.msg);
        }
      })
    }
  },
  created: function() {
    
  }
};
</script>
<style>
.fen{text-align:center;}
</style>